package com.lesso.zgs.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.domain.repository.DeviceRepository;
import com.lesso.zgs.sunflower.infra.assembler.DeviceAssembler;
import com.lesso.zgs.sunflower.model.Device;
import com.lesso.zgs.sunflower.pojo.dto.DeviceDTO;
import com.lesso.zgs.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.DeviceVO;
import org.springframework.stereotype.Service;

/**
 * DeviceDomainService
 *
 * @author zgs
 * @since 2025-07-03
 */
@Service
public class DeviceDomainService {
    private final DeviceRepository deviceRepository;

    public DeviceDomainService(DeviceRepository deviceRepository) {
        this.deviceRepository = deviceRepository;
    }

    public Integer save(DeviceDTO dto) {
        Device device = DeviceAssembler.INSTANCE.dtoToEntity(dto);
        return deviceRepository.save(device);
    }

    public DeviceDTO getById(Long id) {
        Device device = deviceRepository.getById(id);
        return DeviceAssembler.INSTANCE.entityToDto(device);
    }

    public Integer update(DeviceDTO dto) {
        Device device = DeviceAssembler.INSTANCE.dtoToEntity(dto);
        return deviceRepository.update(device);
    }

    public Integer delete(Long id) {
        return deviceRepository.delete(id);
    }

    public Page<DeviceVO> page(DeviceQueryDTO dto) {
        return deviceRepository.getPageList(dto);
    }
} 